// LemCoop
// Copyright (C) 2013  Oliver Naumann <bldrax@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef LEMC_CLIENTCONNECTIONLIST_H
#define LEMC_CLIENTCONNECTIONLIST_H

#include <vector>
#include <string>

#include "clientconnection.h"

/*
* A list of all clients that participate in the current game.
*/
class ClientConnectionList
{
private:
	// The list of all players.
	std::vector<ClientConnection> m_client_list;

public:
	/*
	* Adds a player to the player list (most likely called when someone connected (or in case of the client: if it
	* got a message from the server that another client connected).
	*
	* @param client The client that connected.
	*
	* @return True if the client could be added, otherwise false.
	*/
	bool AddClient(ClientConnection client);

	/*
	* Gets a client based on the internal number. This is for example used it the program wants to iterate through
	* every player.
	*
	* @param number The internal number of the player (this is NOT the guid).
	* @param client A pointer to the ClientConnection with the respective number.
	*
	* @return True if the client has been obtained successfully, else false.
	*/
	bool GetClient(unsigned number, ClientConnection& client);

	/*
	* Gets a client based on the guid. This is used for picking a specified player.
	*
	* @param guid The guid of the player.
	* @param client The ClientConnection where the client is to be stored if it could be obtained.
	*
	* @return True if the client has been obtained successfully, else false.
	*/
	bool GetClient(std::string guid, ClientConnection*& client);

	/*
	* Removes a client from the list based on its internal number.
	*
	* @param number The internal number of the client.
	*
	* @return True if the client was removed, else false.
	*/
	bool RemoveClient(unsigned number);

	/*
	* Removes a client from the list based on its guid (e.g. if the respective client has disconnected).
	*
	* @param guid The guid of the client.
	*
	* @return True if the client was removed, else false.
	*/
	bool RemoveClient(std::string guid);

	/*
	* Removes a client from the list based on its guid (e.g. if the respective client has disconnected) and
	* calculates its position in the list.
	*
	* @param guid The guid of the client.
	* @param number The index that the client with the guid had.
	*
	* @return True if the client was removed, else false.
	*/
	bool RemoveClient(std::string guid, unsigned& number);

	/*
	* Returns the current number of clients.
	*
	* @return The number of known clients.
	*/
	unsigned GetSize();
};

#endif